1

I am following along the example on how to parse XML with Powershell. I copied the contents of the example XML text and tried to parse with given commands. Everything worked OK.

Then I tried to parse my own XML file but immediately after I had issued [xml]$bar = Get-Content test2.xml command, I got the following error:

Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "The '=' character, hexadecimal value 0
x3D, cannot be included in a name. Line 5, position 19."
At line:1 char:1
+ [xml]$bar = Get-Content test2.xml
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (:) [], ArgumentTransformationMetadataException
    + FullyQualifiedErrorId : RuntimeException

So I suppose the mere fact that the contents of the XML file differ affects Powershell's ability to parse XML data?

My XML file contents:

<?xml version="1.0" encoding="UTF-8"?>

<metamarket id="lowvol">
    <market id="asx" marketDir="creditcentraligaapaclve_asx_m" mandatoryNews="False">
        <houseCode="CREDITBAAPACLVE" metahouseCode="CREDITBAAPACLVE"/>
    </market>

    <market id="bru" marketDir="creditcentraligaapaclve_bru_m" mandatoryNews="False">
        <houseCode="CREDITBAAPACLVE" metahouseCode="CREDITBAAPACLVE"/>
    </market>

    <market id="sto" marketDir="creditcentraligaapaclve_sto_m" mandatoryNews="False">
        <houseCode="CREDITBAAPACLVE" metahouseCode="CREDITBAAPACLVE"/>
    </market>
</metamarket>
0

1 Answer 1

2

The error message indicates the source of the problem, though it doesn't specifically indicate that an element name is the problem (emphasis added):

Error: "The '=' character, hexadecimal value 0 x3D, cannot be included in a name. Line 5, position 19."

Element names (node names in general) in XML cannot themselves contain = characters.

By contrast, the = in tokens such as id="lowvol" is a separator between an attribute name and its value.

Your XML mistakenly uses such a token - houseCode="CREDITBAAPACLVE" - directly after an opening tag's <, so that houseCode="CREDITBAAPACLVE" was interpreted as the element name.

The solution is to give your element a proper name, such as house:

<house houseCode="CREDITBAAPACLVE" metahouseCode="CREDITBAAPACLVE"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.