Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / December 2004

Tip: Looking for answers? Try searching our database.

parsing xml document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jack Colletta - 23 Dec 2004 18:31 GMT
I have the following xml file (given to me not created by me)

<?xml version="1.0"?>
<workOrderReleased  
    xmlns="http://www.qad.com/qdoc"
    xmlns:enc="http://www.w3.org/2002/12/soap-encoding"
    xmlns:qcom="http://www.qad.com/qdoc/common"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="workOrderReleasedWithComments-JITS17_1.xsd">
    <workOrderReleased>
        <corhOrderNumber>O1564</corhOrderNumber>
        <corhSequenceNumber>1564</corhSequenceNumber>
        <prdfId>Seat Set</prdfId>
        <workOrder>
            <wordId>20041126-00004403-00000000</wordId>
            <wordDescription>System Generated</wordDescription>
            <wordBatchQty>1</wordBatchQty>
            <wordPreScheduleKey>20040601142450-00001567</wordPreScheduleKey>
            <wordBatchIdSched>1999</wordBatchIdSched>
            <wordBatchSerialSched>1</wordBatchSerialSched>
            <wordReleaseOrder>52</wordReleaseOrder>
            <wordPackOrder>0</wordPackOrder>
            <wordProcessStatus>R</wordProcessStatus>
            <wordProductionStatus>R</wordProductionStatus>
            <wordBackflushStatus>U</wordBackflushStatus>
            <wordPackStatus>U</wordPackStatus>
            <wordHold>false</wordHold>
            <wordCreatedDate>2004-11-26</wordCreatedDate>
            <wordCreatedTime>10:25:05</wordCreatedTime>
            <wordUpdatedDate>2004-11-26</wordUpdatedDate>
            <wordUpdatedTime>11:50:57</wordUpdatedTime>
            <wordReleaseDate>2004-11-26</wordReleaseDate>
            <wordReleaseTime>11:08:58</wordReleaseTime>
        </workOrder>
        <workOrderListVersion>
            <wolvId>00000262</wolvId>
            <wolvVersion>00000001</wolvVersion>
            <wolvDescription>YY</wolvDescription>
        </workOrderListVersion>
        <partList>
            <partId>1004872</partId>
            <paldQty>1</paldQty>
            <paldSkipBackflush>false</paldSkipBackflush>
            <attributeList>
                <attributeType>BROADCASTSTRING-0</attributeType>
                <attnId>LeftSeat</attnId>
                <attvId>Yes</attvId>
            </attributeList>
            <componentList>
                <partId>1004872</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>
            <componentList>
                <partId>1004872-A</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>
            <componentList>
                <partId>1004872-B</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>
            <componentList>
                <partId>1004872-C</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>

        </partList>
        <partList>
            <partId>1004883</partId>
            <paldQty>1</paldQty>
            <paldSkipBackflush>false</paldSkipBackflush>
            <attributeList>
                <attributeType>BROADCASTSTRING-1</attributeType>
                <attnId>RightSeat</attnId>
                <attvId>Yes</attvId>
            </attributeList>
            <componentList>
                <partId>1004883</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>
            <componentList>
                <partId>1004883-A</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>
            <componentList>
                <partId>1004883-B</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>
            <componentList>
                <partId>1004883-C</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>
            <componentList>
                <partId>1004883-D</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>
        </partList>
        <partList>
            <partId>100777</partId>
            <paldQty>1</paldQty>
            <paldSkipBackflush>false</paldSkipBackflush>
            <attributeList>
                <attributeType>BROADCASTSTRING-2</attributeType>
                <attnId>RightSeat</attnId>
                <attvId>Yes</attvId>
            </attributeList>
            <componentList>
                <partId>100777</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>
            <componentList>
                <partId>100777-A</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>
            <componentList>
                <partId>100777-B</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>
            <componentList>
                <partId>100777-C</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>
            <componentList>
                <partId>100777-D</partId>
                <bomsQtyPer>1</bomsQtyPer>
            </componentList>
        </partList>

        <shippableAssemblyUnit>
            <asshId>Seatset_SAU</asshId>
            <assuId>Seatset_AU</assuId>
            <wcelId>Seatsets_WC</wcelId>
            <assemblyUnit>
                <assuId>LeftSeat_AU</assuId>
                <wcelId>LSEAT_WC</wcelId>
            </assemblyUnit>
            <assemblyUnit>
                <assuId>RightSeat_AU</assuId>
                <wcelId>RSEAT_WC</wcelId>
            </assemblyUnit>
        </shippableAssemblyUnit>
        <packagingDetails>
            <assuId>LeftSeat_AU</assuId>
            <packageType>Rack</packageType>
            <pkunShortName>LSRACK</pkunShortName>
            <pckgPackageNumber>pk1</pckgPackageNumber>
            <pkctSlotNumber>1</pkctSlotNumber>
        </packagingDetails>
        <packagingDetails>
            <assuId>RightSeat_AU</assuId>
            <packageType>Rack</packageType>
            <pkunShortName>RSRACK</pkunShortName>
            <pckgPackageNumber>pk2</pckgPackageNumber>
            <pkctSlotNumber>1</pkctSlotNumber>
        </packagingDetails>
    </workOrderReleased>
</workOrderReleased>

I am attempting to parse out the <partList> elements.  If I remove all the
references in the first <workOrderReleased> element the following logic
works.  If I use the complete document I get nodes.count = 0.

xmlLogFileName_logFile = "20041126-00004403-00000000a.xml"
           fileString = xmlLogFileName_logFile
       
           Dim xmlDoc As New XmlDocument
           xmlDoc.Load(fileString)

           Dim nsmgr As XmlNamespaceManager

           nsmgr = New XmlNamespaceManager(xmlDoc.NameTable)

           nsmgr.AddNamespace("qd", "http://ww.qad.com/qdoc")
           nsmgr.AddNamespace("enc",
"http://www.w3.org/2002/12/soap-encoding")
           nsmgr.AddNamespace("qcom", "http://www.qad.com/qdoc/common")
           nsmgr.AddNamespace("xsi",
"http://www.w3.org/2001/XMLSchema-instance")

           Dim eResults As XmlNode
           eResults = xmlDoc.DocumentElement

           Dim nodes As XmlNodeList
           nodes =
eResults.SelectNodes("/workOrderReleased/workOrderReleased/partList", nsmgr)

           Dim nattributeType As String =
xmlDoc.NameTable.Get("attributeType")
           Dim nattnId As String = xmlDoc.NameTable.Get("attnId")
           Dim nattvId As String = xmlDoc.NameTable.Get("attvId")

           Dim x = 0
           If (Not nodes Is Nothing) Then
               Console.WriteLine("Number of interactions = " &
CStr(nodes.Count))
               For Each eInteraction As XmlNode In nodes

                   Dim nodesInner As XmlNodeList
                   nodesInner = eInteraction.SelectNodes("attributeList")
                 
                   If (Not nodesInner Is Nothing) Then
                       For Each ePoint As XmlNode In nodesInner
                           
            Dim eChild As XmlNode = ePoint.FirstChild
                           
                           Dim attributeType As String
                           Dim attnId As String
                           Dim attvId As String

                           While (Not eChild Is Nothing)
                               If (eChild.NodeType = XmlNodeType.Element)
Then
                                   If eChild.LocalName = nattributeType Then
                                       attributeType =
eChild.FirstChild.Value
                                   ElseIf eChild.LocalName = nattnId Then
                                       nattnId = eChild.FirstChild.Value
                                   ElseIf eChild.LocalName = nattvId Then
                                       nattvId = eChild.FirstChild.Value
                                   End If
                               End If
                               eChild = eChild.NextSibling
                           End While

                          Console.WriteLine("attributes = " & x & " : " &
attributeType & " : " & nattnId & " : " & nattvId)
                       Next
                       x = x + 1
                   End If
               Next
           End If

Any help would be great....

Thank you
Jack Colletta
Nick Malik [Microsoft] - 25 Dec 2004 18:43 GMT
Hi Jack,

In the source XML document, this entry is the default namespace:
>             nsmgr.AddNamespace("qd", "http://ww.qad.com/qdoc")

you gave it a prefix.  Therefore, when you are providing your XPath query,
you need to provide the prefix:

Change the SelectNodes line to:
nodes =
eResults.SelectNodes("/qd:workOrderReleased/qd:workOrderReleased/qd:partList
", nsmgr)

give that a shot.  I'm no expert at XPath, but I've had my fair share of
run-ins with prefixes.
Hope this helps,

Signature

--- Nick Malik [Microsoft]
   MCSD, CFPS, Certified Scrummaster
   http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
  I do not answer questions on behalf of my employer.  I'm just a
programmer helping programmers.
--

> I have the following xml file (given to me not created by me)
>
[quoted text clipped - 231 lines]
> Thank you
> Jack Colletta
garbage@colletta.com - 26 Dec 2004 12:18 GMT
Thanks Nick,

I will give it a try and let you know.
Jack Colletta - 27 Dec 2004 12:21 GMT
Thanks Nick,

I tried what you said, but I still did not parse the partlist section.  I am
finding that working with XML files can be tricky.

> Hi Jack,
>
[quoted text clipped - 250 lines]
> > Thank you
> > Jack Colletta
Oleg Tkachenko [MVP] - 27 Dec 2004 12:44 GMT
> I have the following xml file (given to me not created by me)
>
> <?xml version="1.0"?>
> <workOrderReleased  
>     xmlns="http://www.qad.com/qdoc"

...

>             nsmgr.AddNamespace("qd", "http://ww.qad.com/qdoc")

Can you see a typo here?
And use "/qd:workOrderReleased/qd:workOrderReleased/qd:partList" of course.

Signature

Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

garbage@colletta.com - 27 Dec 2004 13:55 GMT
The only thing I see is that xmlns does not have a prefix and I added
one to the namespace manger called qd...  I have been working on this
for a while and I am getting punchy
Nick Malik [Microsoft] - 27 Dec 2004 14:15 GMT
touche'

The URL is misspelled.

> >             nsmgr.AddNamespace("qd", "http://www.qad.com/qdoc")

Signature

--- Nick Malik [Microsoft]
   MCSD, CFPS, Certified Scrummaster
   http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
  I do not answer questions on behalf of my employer.  I'm just a
programmer helping programmers.
--

>
> > I have the following xml file (given to me not created by me)
[quoted text clipped - 9 lines]
> Can you see a typo here?
> And use "/qd:workOrderReleased/qd:workOrderReleased/qd:partList" of course.
garbage@colletta.com - 27 Dec 2004 14:20 GMT
Oleg,
Thanks so much..I owe you one.  I can't believe I missed it.

Jack
Jack Colletta - 27 Dec 2004 14:47 GMT
Nick you too, thanks

> Oleg,
> Thanks so much..I owe you one.  I can't believe I missed it.
>
> Jack

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.