برگزیده های پرشین تولز

XML parser !!

Shahed

کاربر قدیمی پرشین تولز
تاریخ عضویت
30 ژوئن 2003
نوشته‌ها
7,289
لایک‌ها
34
محل سکونت
mt.cgi
سلام
اساتید !!
یه فایل ایکس ام ال هست ... چیزی تو مایه های پست های وبلاگ ..
که هر پست چند تا فیلد داره و هر فیلد توی یه تگ خاص هست ...

چجوری میشه عینه انسون خوند این xml رو؟؟

کد:
<POST>
<PostID>1</PostID>
<Title>title here</Title>
<Body>body here</Body>
</POST>
 
<POST>
<PostID>2</PostID>
<Title>title here</Title>
<Body>body here</Body>
</POST>
تو این مایه هاست !
 

firebird

Registered User
تاریخ عضویت
2 جولای 2005
نوشته‌ها
1,424
لایک‌ها
10
سن
46

Shahed

کاربر قدیمی پرشین تولز
تاریخ عضویت
30 ژوئن 2003
نوشته‌ها
7,289
لایک‌ها
34
محل سکونت
mt.cgi
والا خیلی گشتم ! از هیچکدوم ازاینا جواب نگرفتم !! احتمالا مشکل از منه !! نمیدونم چیه جریان !!

میشه با یه مثالی چیزی بزارید؟
 

Shahed

کاربر قدیمی پرشین تولز
تاریخ عضویت
30 ژوئن 2003
نوشته‌ها
7,289
لایک‌ها
34
محل سکونت
mt.cgi
لول ! مشکل رو فهمیدم کجاست !! XML ام یکم مورد داشته ! xml ای که مثال زدم رو ببینین تو پست اول
باید داخل یه تگ کلی باشه ..
مثلا اینجوری:

کد:
<BLOG>
 
<POST>
<PostID>1</PostID>
<Title>title here</Title>
<Body>body here</Body>
</POST>
 
<POST>
<PostID>2</PostID>
<Title>title here</Title>
<Body>body here</Body>
</POST>
 
</BLOG>
 

Shahed

کاربر قدیمی پرشین تولز
تاریخ عضویت
30 ژوئن 2003
نوشته‌ها
7,289
لایک‌ها
34
محل سکونت
mt.cgi
پوووف !! آقا من دیگه داره مخم سوت میکشه !! ترکیدم زیر این XML !!

این رو ببینید:

کد:
<PubmedArticleSet>
<PubmedArticle>
    <MedlineCitation Owner Status>
        <PMID>17845396</PMID>
        <DateCreated>
            <Year>2007</Year>
            <Month>09</Month>
            <Day>11</Day>
        </DateCreated>
        <Article PubModel>
            <Journal>
                <ISSN IssnType>1744-9979</ISSN>
                <JournalIssue CitedMedium>
                    <Volume>11</Volume>
                    <Issue>5</Issue>
                    <PubDate>
                        <Year>2007</Year>
                        <Month>Oct</Month>
                    </PubDate>
                </JournalIssue>
                <Title>Therapeutic apheresis and dialysis : official peer-reviewed journal of the International Society for Apheresis, the Japanese Society for Apheresis, the Japanese Society for Dialysis Therapy</Title>
            </Journal>
            <ArticleTitle>Hepatitis g virus exposure in dialysis staff.</ArticleTitle>
            <Pagination>
                <MedlinePgn>370-4</MedlinePgn>
            </Pagination>
            <Abstract>
                <AbstractText>Hepatitis G virus (HGV) is a blood-borne virus. Some present data demonstrate an occupational risk of HGV infection in medical staff of dialysis units. The aim of this investigation was to assess the prevalence of HGV exposure in dialysis staff. This study was performed in a main dialysis unit in Iran. In 27 dialysis staff, HGV exposure was detected serologically by the presence of anti HGV envelope protein E2 (anti-E2) by an enzyme-linked immunosorbent assay, and compared with 77 hemodialysis (HD) and 13 continuous ambulatory peritoneal dialysis (CAPD) patients. All of them were also screened for hepatitis B surface antigen (HBsAg), hepatitis B surface antibody (anti-HBs), and hepatitis C antibody (anti-HCV). A low prevalence of HGV exposure was found in the dialysis staff (0%), which nearly corresponded to the prevalence of the dialysis patients (HD 3.89%, CAPD 0%). The prevalence of anti-HCV and anti-HBs in staff was 37.03% and 33.33%, respectively, which was higher than HGV anti-E2. The prevalence of HGV exposure was low in dialysis staff in our study, and was near to the prevalence of HGV exposure in dialysis patients. Therefore, it can be concluded that the occupational risk for HGV exposure in our investigation was minimal.</AbstractText>
            </Abstract>
            <Affiliation>Clinical Research Department, Pasteur Institute of Iran, Tehran, Iran.</Affiliation>
            <AuthorList CompleteYN>
                <Author ValidYN>
                    <LastName>Eslamifar</LastName>
                    <ForeName>Ali</ForeName>
                    <Initials>A</Initials>
                </Author>
                <Author ValidYN>
                    <LastName>Hamkar</LastName>
                    <ForeName>Rasool</ForeName>
                    <Initials>R</Initials>
                </Author>
                <Author ValidYN>
                    <LastName>Ramezani</LastName>
                    <ForeName>Amitis</ForeName>
                    <Initials>A</Initials>
                </Author>
                <Author ValidYN>
                    <LastName>Ahmadi</LastName>
                    <ForeName>Farrokhlagha</ForeName>
                    <Initials>F</Initials>
                </Author>
                <Author ValidYN>
                    <LastName>Gachkar</LastName>
                    <ForeName>Latif</ForeName>
                    <Initials>L</Initials>
                </Author>
                <Author ValidYN>
                    <LastName>Jalilvand</LastName>
                    <ForeName>Somayeh</ForeName>
                    <Initials>S</Initials>
                </Author>
                <Author ValidYN>
                    <LastName>Adibi</LastName>
                    <ForeName>Ladan</ForeName>
                    <Initials>L</Initials>
                </Author>
                <Author ValidYN>
                    <LastName>Khameneh</LastName>
                    <ForeName>Ali</ForeName>
                    <Initials>A</Initials>
                </Author>
                <Author ValidYN>
                    <LastName>Atabak</LastName>
                    <ForeName>Shahnaz</ForeName>
                    <Initials>S</Initials>
                </Author>
                <Author ValidYN>
                    <LastName>Ghadimi</LastName>
                    <ForeName>Ramin</ForeName>
                    <Initials>R</Initials>
                </Author>
                <Author ValidYN>
                    <LastName>Aghakhani</LastName>
                    <ForeName>Arezoo</ForeName>
                    <Initials>A</Initials>
                </Author>
            </AuthorList>
            <Language>eng</Language>
            <PublicationTypeList>
                <PublicationType>Journal Article</PublicationType>
            </PublicationTypeList>
        </Article>
        <MedlineJournalInfo>
            <Country>Australia</Country>
            <MedlineTA>Ther Apher Dial</MedlineTA>
            <NlmUniqueID>101181252</NlmUniqueID>
        </MedlineJournalInfo>
        <CitationSubset>IM</CitationSubset>
    </MedlineCitation>
    <PubmedData>
        <History>
            <PubMedPubDate PubStatus>
                <Year>2007</Year>
                <Month>9</Month>
                <Day>12</Day>
                <Hour>9</Hour>
                <Minute>0</Minute>
            </PubMedPubDate>
            <PubMedPubDate PubStatus>
                <Year>2007</Year>
                <Month>9</Month>
                <Day>12</Day>
                <Hour>9</Hour>
                <Minute>0</Minute>
            </PubMedPubDate>
        </History>
        <PublicationStatus>ppublish</PublicationStatus>
        <ArticleIdList>
            <ArticleId IdType>TAP501</ArticleId>
            <ArticleId IdType>10.1111/j.1744-9987.2007.00501.x</ArticleId>
            <ArticleId IdType>17845396</ArticleId>
        </ArticleIdList>
    </PubmedData>
</PubmedArticle>
 
<PubmedArticle>
    <MedlineCitation Status Owner>
        <PMID>17786579</PMID>
        <DateCreated>
            <Year>2007</Year>
            <Month>9</Month>
            <Day>5</Day>
        </DateCreated>
        <Article PubModel>
            <Journal>
                <ISSN IssnType>0301-1623</ISSN>
                <JournalIssue CitedMedium>
                    <PubDate>
                        <Year>2007</Year>
                        <Month>Sep</Month>
                        <Day>5</Day>
                    </PubDate>
                </JournalIssue>
            </Journal>
            <ArticleTitle>Hepatitis G virus exposure in dialysis patients.</ArticleTitle>
            <Pagination>
                <MedlinePgn/>
            </Pagination>
            <Abstract>
                <AbstractText>BACKGROUND: Hepatitis G virus (HGV) is a blood-borne virus. The predominant route of its transmission is parenteral. The aim of this study was to assess the frequency of HGV exposure in haemodialysis (HD) and continuous ambulatory peritoneal dialysis (CAPD) patients in Iran. METHODS: This study was performed in a major dialysis centre in Tehran, Iran. The study cohort consisted of 77 patients on HD and 13 patients on CAPD. The presence of anti-HGV envelope protein E2 (anti-E2) in the blood serum, as determined by means of an ELISA assay, indicated HGV exposure. All patients were also screened for hepatitis B surface antigen (HBsAg), hepatitis B surface antibody (anti-HBs) and hepatitis C antibody (anti-HCV). In patients who tested positive for anti-E2, HGV RNA was detected by RT-PCR using primers derived from the NS5A region of the viral genome. RESULTS: In total, 3.89% of the HD patients and none of the CAPD patients tested positive for anti-E2. None of the patients tested positive for HGV RNA. The mean age of the anti-E2-positive patients was 53.3 +/- 26.5 years, with 66.66% having previously received blood transfusion. The mean duration of dialysis of the anti-E2-positive patients was 68 +/- 64 months. Co-infection with HCV or HBV was not observed in the anti-E2 positive patients. CONCLUSION: The rate of exposure to HGV was low among the dialysis patients in our study. The appearance of anti-E2 was accompanied by clearance of serum HGV-RNA. No relationship was noted between HGV exposure and age, sex, history of blood transfusion, time on dialysis and HCV or HBV markers.</AbstractText>
            </Abstract>
            <Affiliation>Clinical Research Department, Pasteur Institute of Iran, No 69, Pasteur Ave., Tehran, 13164, Iran, [email protected].</Affiliation>
            <AuthorList>
                <Author>
                    <LastName>Eslamifar</LastName>
                    <FirstName>Ali</FirstName>
                    <Initials>A</Initials>
                </Author>
                <Author>
                    <LastName>Hamkar</LastName>
                    <FirstName>Rasool</FirstName>
                    <Initials>R</Initials>
                </Author>
                <Author>
                    <LastName>Ramezani</LastName>
                    <FirstName>Amitis</FirstName>
                    <Initials>A</Initials>
                </Author>
                <Author>
                    <LastName>Ahmadi</LastName>
                    <FirstName>Farrokhlagha</FirstName>
                    <Initials>F</Initials>
                </Author>
                <Author>
                    <LastName>Gachkar</LastName>
                    <FirstName>Latif</FirstName>
                    <Initials>L</Initials>
                </Author>
                <Author>
                    <LastName>Jalilvand</LastName>
                    <FirstName>Somayeh</FirstName>
                    <Initials>S</Initials>
                </Author>
                <Author>
                    <LastName>Adibi</LastName>
                    <FirstName>Ladan</FirstName>
                    <Initials>L</Initials>
                </Author>
                <Author>
                    <LastName>Atabak</LastName>
                    <FirstName>Shahnaz</FirstName>
                    <Initials>S</Initials>
                </Author>
                <Author>
                    <LastName>Khameneh</LastName>
                    <FirstName>Ali</FirstName>
                    <Initials>A</Initials>
                </Author>
                <Author>
                    <LastName>Ghadimi</LastName>
                    <FirstName>Ramin</FirstName>
                    <Initials>R</Initials>
                </Author>
                <Author>
                    <LastName>Aghakhani</LastName>
                    <FirstName>Arezoo</FirstName>
                    <Initials>A</Initials>
                </Author>
            </AuthorList>
            <Language>ENG</Language>
            <PublicationTypeList>
                <PublicationType>JOURNAL ARTICLE</PublicationType>
            </PublicationTypeList>
            <ArticleDate DateType>
                <Year>2007</Year>
                <Month>9</Month>
                <Day>5</Day>
            </ArticleDate>
        </Article>
        <MedlineJournalInfo>
            <MedlineTA>Int Urol Nephrol</MedlineTA>
            <NlmUniqueID>0262521</NlmUniqueID>
        </MedlineJournalInfo>
    </MedlineCitation>
    <PubmedData>
        <History>
            <PubMedPubDate PubStatus>
                <Year>2007</Year>
                <Month>2</Month>
                <Day>24</Day>
            </PubMedPubDate>
            <PubMedPubDate PubStatus>
                <Year>2007</Year>
                <Month>7</Month>
                <Day>25</Day>
            </PubMedPubDate>
            <PubMedPubDate PubStatus>
                <Year>2007</Year>
                <Month>9</Month>
                <Day>5</Day>
            </PubMedPubDate>
            <PubMedPubDate PubStatus>
                <Year>2007</Year>
                <Month>9</Month>
                <Day>6</Day>
                <Hour>9</Hour>
                <Minute>0</Minute>
            </PubMedPubDate>
            <PubMedPubDate PubStatus>
                <Year>2007</Year>
                <Month>9</Month>
                <Day>6</Day>
                <Hour>9</Hour>
                <Minute>0</Minute>
            </PubMedPubDate>
        </History>
        <PublicationStatus>aheadofprint</PublicationStatus>
        <ArticleIdList>
            <ArticleId IdType>10.1007/s11255-007-9267-x</ArticleId>
            <ArticleId IdType>17786579</ArticleId>
        </ArticleIdList>
    </PubmedData>
</PubmedArticle>

خروجی XML سایت pubmed هست !!
میخوام تگ PMID و ArticleTitle به طور لیست وار کنار هم در بیاد .. برای ریختن توی دیتابیس میخوام.
این رو الان من چیکار کنم؟ نوع XML خاصی هست؟ چرا عینه آدم کار نمیکنه؟
یکی بیاد کمک کنه دعاش کنم :(
 

Shahed

کاربر قدیمی پرشین تولز
تاریخ عضویت
30 ژوئن 2003
نوشته‌ها
7,289
لایک‌ها
34
محل سکونت
mt.cgi
تقریبا مشکل رو فهمیدم !
xml من بعضی تگهاش اسپیس داره تو خودش ! بیخودی ! بخاطر همین اینا نمیتونن درست parse ش کنن !
تا الان کل phpclasses رو ریختم بیرون ! هیچی پیدا نکردم به درد بخور باشه !! کسی راهی به ذهنش میرسه عینه آدم بتونم اون دوتا تگ رو بخونم؟
 

Shahed

کاربر قدیمی پرشین تولز
تاریخ عضویت
30 ژوئن 2003
نوشته‌ها
7,289
لایک‌ها
34
محل سکونت
mt.cgi
confetti.gif
loveshower.gif
greenstars.gif

حل شد!
 

Shahed

کاربر قدیمی پرشین تولز
تاریخ عضویت
30 ژوئن 2003
نوشته‌ها
7,289
لایک‌ها
34
محل سکونت
mt.cgi
کدی که استفاده میکنمرو میزارم !! بلکن یکی به کارش اومد !! فعلا که داره مثل انسون کار میکنه !!

PHP:
<?
// Extracts content from XML tag
function GetElementByName ($xml, $start, $end) {
    global $pos;
    $startpos = strpos($xml, $start);
    if ($startpos === false) {
        return false;
    }
    $endpos = strpos($xml, $end);
    $endpos = $endpos+strlen($end);    
    $pos = $endpos;
    $endpos = $endpos-$startpos;
    $endpos = $endpos - strlen($end);
    $tag = substr ($xml, $startpos, $endpos);
    $tag = substr ($tag, strlen($start));
    return $tag;
}
// Open and read xml file. You can replace this with your xml data.
$file = "data.xml";
$pos = 0;
$Nodes = array();
if (!($fp = fopen($file, "r"))) {
    die("could not open XML input");
}
while ($getline = fread($fp, 4096)) {
    $data = $data . $getline;
}
$count = 0;
$pos = 0;
// Goes throw XML file and creates an array of all <XML_TAG> tags.
while ($node = GetElementByName($data, "<PubmedArticle>", "</PubmedArticle>")) {
    $Nodes[$count] = $node;
    $count++;
    $data = substr($data, $pos);
}
// Gets infomation from tag siblings.
for ($i=0; $i<$count; $i++) {
echo "<b>PMID: </b>";
echo $PMID = GetElementByName($Nodes[$i], "<PMID>", "</PMID>");
echo "<br />";
echo "<b>title: </b>";
echo $Title = GetElementByName($Nodes[$i], "<Title>", "</Title>");
echo "<br />";
echo "<b>ArticleTitle: </b>";
echo $ArticleTitle = GetElementByName($Nodes[$i], "<ArticleTitle>", "</ArticleTitle>");
echo "<hr />";
}
?>
 
بالا